package com.tenement.controller.backend;

import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tenement.base.constants.SysmConstants.state;
import com.tenement.base.exception.ParameterException;
import com.tenement.mybatis.entity.House;
import com.tenement.service.interfaces.IHouseService;

@Controller
public class MessageManageController {

	private static final Log logger = LogFactory.getLog(MessageManageController.class);

	@Autowired
	private IHouseService iHouseService;

	/**
	 * 进入信息审核页面
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "toMsgReviewHtml.action")
	public String toMsgReviewHtml(HttpServletRequest request) {
		logger.info("【获取房源信息审核列表】");
		request.setAttribute("houseList", iHouseService.getHouseNoReview());
		return "view/backend_system/msg_review";
	}

	@RequestMapping(value = "modifyHReviewStatus.action")
	public @ResponseBody String modifyHReviewStatus(HttpServletRequest request, @RequestBody String data,
			String message, String u_id) {
		logger.info("【房源信息发布审核】");
		try {
			if (data == null || "".equals(data)) {
				throw new ParameterException("【参数为空】");
			}
			JSONObject json = JSON.parseObject(data);
			String action = json.getString("action");
			String h_id = json.getString("h_id");
			int actionId = Integer.parseInt(action);
			House house = new House();
			logger.info(action+"  "+h_id);
			house.sethId(Integer.parseInt(h_id));
			house.sethReviewStatus(actionId);
			boolean b = iHouseService.modifyHReviewStatus(house);
			if (b) {
				return state.Success;
			} else {
				return state.Failed;
			}
		} catch (ParameterException p) {
			p.printStackTrace();
		}
		return state.Failed;
	}

}
